package com.opta.entity;

import org.optaplanner.core.api.solver.event.BestSolutionChangedEvent;
import org.optaplanner.core.api.solver.event.SolverEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Gavin
 * @name BtoSolverEventListener
 * @description 最优成绩监听器
 * @date 2020/4/23 13:29
 * @since 1.0
 */

public class OrderSolverEventListener implements SolverEventListener<OrderSolution> {

    private final Logger log = LoggerFactory.getLogger(OrderSolverEventListener.class);

    @Override
    public void bestSolutionChanged(BestSolutionChangedEvent<OrderSolution> event) {
        try {
            log.info("最优结果为:" + event.getNewBestSolution().getOrders().toString());
            SolutionResult.Result result = new SolutionResult.Result(event.getNewBestSolution(), event.getNewBestScore());
            SolutionResult.add(result);
            log.info("执行结果 班组产能:" + result.getBestSolution().getLineSupplyMap());
        } catch (Exception ex) {
            log.info("获取最优结果失败!");
        }
    }
}
